/**
 * Definition for singly-linked list.
 * public class ListNode {
 *     int val;
 *     ListNode next;
 *     ListNode() {}
 *     ListNode(int val) { this.val = val; }
 *     ListNode(int val, ListNode next) { this.val = val; this.next = next; }
 * }
 */
//反转链表
class code2 {
    public ListNode reverseList(ListNode head) {
        ListNode prev = null;

        while(head != null ) {
            ListNode headNext = head.next;
            head.next = prev;
            prev = head;
            head = headNext;
        }

        return prev;
    }
}